package com.codename1.samples;


import com.codename1.charts.util.ColorUtil;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
import com.codename1.ui.plaf.Border;
import com.codename1.ui.plaf.Style;

/**
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose 
 * of building native mobile applications using Java.
 */
public class GradientAlphaTest {

    private Form current;
    private Resources theme;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if(err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });        
    }
    
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        Form hi = new Form("Hi World", BoxLayout.y());
        
        Label label = new Label("Hello World");
        label.getAllStyles().setBorder(Border.createEmpty());
      // Apply desired background and text colors and transparency
      label.getAllStyles().setPadding(25, 25, 25, 25);
      label.getAllStyles().setBgColor(ColorUtil.WHITE);
      label.getAllStyles().setFgColor(ColorUtil.WHITE);
      label.getAllStyles().setBgTransparency(255);
      // Now define gradient settings
      label.getAllStyles().setBackgroundGradientStartColor(ColorUtil.argb((int)(0.4*255), 0 , 0, 0xff));
      label.getAllStyles().setBackgroundGradientRelativeSize(0.5f);
      label.getAllStyles().setBackgroundGradientRelativeY(0.5f);
      label.getAllStyles().setBackgroundGradientEndColor(ColorUtil.argb((int)(0.7*255), 0 , 0, 0xff));
      // Make sure the code gradient settings are not overriden in thenative theme

        label.getAllStyles().setBackgroundType(Style.BACKGROUND_GRADIENT_LINEAR_VERTICAL, false);
        hi.add(label);
        
        label.setWidth(400);
        label.setHeight(100);
        hi.add(new Label("Hello World Mutable", label.toImage()));
        
        label = new Label("Hello World (Radial)");
        label.getAllStyles().setBorder(Border.createEmpty());
      // Apply desired background and text colors and transparency
      label.getAllStyles().setPadding(25, 25, 25, 25);
      label.getAllStyles().setBgColor(ColorUtil.WHITE);
      label.getAllStyles().setFgColor(ColorUtil.WHITE);
      label.getAllStyles().setBgTransparency(255);
      // Now define gradient settings
      label.getAllStyles().setBackgroundGradientStartColor(ColorUtil.argb((int)(0.4*255), 0 , 0, 0xff));
      label.getAllStyles().setBackgroundGradientRelativeSize(0.5f);
      label.getAllStyles().setBackgroundGradientRelativeY(0.5f);
      label.getAllStyles().setBackgroundGradientEndColor(ColorUtil.argb((int)(0.7*255), 0 , 0, 0xff));
      // Make sure the code gradient settings are not overriden in thenative theme

        label.getAllStyles().setBackgroundType(Style.BACKGROUND_GRADIENT_RADIAL, false);
        hi.add(label);
        
        label.setWidth(400);
        label.setHeight(100);
        
        hi.add(new Label("Hello World Mutable Radial", label.toImage()));
        
        
        hi.show();
    }

    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }
    
    public void destroy() {
    }

}
